package com.xplusplus.security.controller;

import com.xplusplus.security.domain.Hello;
import com.xplusplus.security.repository.HelloRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author: zhouweixin
 * @Description:
 * @Date: Created in 13:41 2018/5/7
 * @Modified By:
 */
@RestController
@RequestMapping(value = "/hello")
@Api(tags = "hello接口")
public class HelloController {
    @Autowired
    private HelloRepository helloRepository;

    @GetMapping(value = "/hello")
    public String hello() {
        System.out.println("=============================");
        System.out.println("hello hello hello!");
        System.out.println("=============================");
        return "Hello Security";
    }

    @GetMapping(value = "/add1")
    @ApiOperation(value = "新增1")
    public Hello add(Hello hello) {
        hello.setDate2(new Date());
        return helloRepository.save(hello);
    }

    @GetMapping(value = "/add2")
    @ApiOperation(value = "新增2")
    public Hello update(@ApiParam(value = "时间 yyyy-MM-dd HH:mm:ss")
                        @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) {
        Hello hello = new Hello();
        hello.setDate1(date);
        hello.setDate2(new Date());
        return helloRepository.save(hello);
    }
}
